
import ui
from data import *
import world

# mapping between the id sent by the server and the id in gumpart.mul
BUFF_ICONS = {
    0x3e9: 0x754C,
    0x3ea: 0x754A,
    0x3ed: 0x755E,
    0x3ee: 0x7549,
    0x3ef: 0x7551,
    0x3f0: 0x7556,
    0x3f1: 0x753A,
    0x3f2: 0x754D,
    0x3f3: 0x754E,
    0x3f4: 0x7565,
    0x3f5: 0x753B,
    0x3f6: 0x7543,
    0x3f7: 0x7544,
    0x3f8: 0x7546,
    0x3f9: 0x755C,
    0x3fa: 0x755F,
    0x3fb: 0x7556,
    0x3fc: 0x7554,
    0x3fd: 0x7540,
    0x3fe: 0x7568,
    0x3ff: 0x754F,
    0x400: 0x7550,
    0x401: 0x7553,
    0x402: 0x753E,
    0x403: 0x755D,
    0x404: 0x7563,
    0x405: 0x7562,
    0x406: 0x753F,
    0x407: 0x7559,
    0x408: 0x7557,
    0x409: 0x754B,
    0x40a: 0x753D,
    0x40b: 0x7561,
    0x40c: 0x7558,
    0x40d: 0x755B,
    0x40e: 0x7560,
    0x40f: 0x7541,
    0x410: 0x7545,
    0x411: 0x7552,
    0x412: 0x7569,
    0x413: 0x7548,
    0x414: 0x755A,
    0x415: 0x753C,
    0x416: 0x7547,
    0x417: 0x7567,
    0x418: 0x7542,
}

def populateGump(g):
    bufflist = world.getPlayer().buffs

    g.addBackground((0, 0, len(bufflist) * 30 + 8, 36), 3000)

    x = 4
    # bufflist is a list of tuples
    # (icon id, title, desc, seconds to expire)
    for cur in bufflist:
        if cur[0] in BUFF_ICONS:
            g.addImage((x, 4), Texture(TextureSource.GUMPART, BUFF_ICONS[cur[0]]))
            x += 30
        else:
            print "Unknown buff icon", cur[0], cur[1]
        # TODO: do something with the description and title
        # TODO: display expire time

def create(args):
    g = ui.GumpMenu("buffbar", args.get("x", 50), args.get("y", 50))

    populateGump(g)

def refreshBuffs(gump):
    gump.clearComponents()
    populateGump(gump)
